<?php

	$indent = 0;
	function e($s)
	{
		global $indent;
		echo str_repeat('&mdash;&nbsp;',$indent)."$s<br />";
	}

	function ein($s)
	{
		global $indent;
		e($s);
		$indent++;
	}

	function eout($s = '')
	{
		global $indent;
		$indent--;
		if ($s != '')
		{
			e("$s<br />");
		}
	}

	function ls($s)
	{

		if (isset(Locale::$current->strings[$s]))
		{
			return Locale::$current->strings[$s];
		}
		else
		{
			return $s;
		}
	}

// UTILITIES
// *********************************************************

	// Can $obj write the property $property
	function is_writable_by($obj, $class_name_array, $property)
	{
		if (array_key_exists($property, $class_name_array) && $obj)
		{
			foreach ($class_name_array[$property] as $class_name)
			{
				if ($obj instanceof $class_name)
				{
					return true;
				}
			}
			return false;
		}
		else
		{
			return false;
		}
	}

	function get_caller_object()
	{
		$trace = debug_backtrace();
		if (array_key_exists('object',$trace[2]))
		{
			return $trace[2]['object'];
		}
		else
		{
			return NULL;
		}
	}

	function get_caller_class()
	{
		$trace = debug_backtrace();
		return $trace[2]['class'];
	}

	function current_page()
	{
		return substr($_SERVER["SCRIPT_NAME"], strrpos($_SERVER["SCRIPT_NAME"], '/')+1, -4);
	}

	function page_title()
	{
		return ls(current_page());
	}

	function age($birth)
	{
		$anyo_nacimiento = $birth;
		$anyo_actual = date("Y");
		
		$edad = $anyo_actual - $anyo_nacimiento;
		
		$ahora = gettimeofday();
		$ahora = $ahora['sec'];
		$cumpleanyos = mktime(0,0,0,2,23,$anyo_actual);
		if ($ahora < $cumpleanyos)
		{
			$edad--;
		}
		return $edad;
	}
	
	function array_get($array, $key)
	{
		if (array_key_exists($key, $array))
		{
			return $array[$key];
		}
		else {
			return '';
		}
	}
	
?>
